from selenium import webdriver
import time
import urllib3
from aip import AipOcr
import logging
import os
from PIL import Image
APP_ID = '11243469'
API_KEY = 'LkbGHrd9BVGtQBvMpZLCG225'
SECRET_KEY = 'Hs7z1TfNeVQFr4QOqfi69vpkXsUIO81Q'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s -%(levelname)s -%(process)d -%(module)s -%(funcName)s -%(message)s')
def getCheckCode():
    
    http = urllib3.PoolManager()
    r=http.request(
        'GET',
        'http://xf.faxuan.net/service/gc.html?timestamp='+str(int(time.time())*1000),
        headers={
            'Cookie':"rid=b796f088075f3ece293eb3cd26f6dd78;_qddaz=QD.6nokiz.8pfjds.jh7ju4cc;_qdda=3-1.1;_qddab=3-oxhwy3.jh7ju4cc;_qddamta_4006570518=3-0;tencentSig=565276672"
        }
        )
    img=r.data
    f=open(os.path.dirname(__file__)+"\\123.jpg","wb")
    f.write(img)
    f.close()
    #im=Image.load(img)
    #im.show()
    options = {}
    options["language_type"] = "ENG"
    options["probability"] = "true"
    checkcodeinfo=client.basicGeneral(img,options)
    logging.debug(checkcodeinfo.get('error_msg'))
    return checkcodeinfo
codeinfo=getCheckCode()
print(codeinfo)
print(codeinfo['words_result'][0]['words'])